package com.ruoyi.web.config;

import com.aliyun.openservices.ons.api.PropertyKeyConst;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

/**
 * 阿里云MQ配置
 *
 * @author jason
 */
@Data
@Configuration
@ConfigurationProperties(prefix = "aliyun.mq")
public class AliyunMQConfig {

    /**
     * 阿里云 oss 公钥
     */
    private String accessKeyId;

    /**
     * 阿里云 oss 私钥
     */
    private String accessKeySecret;

    /**
     * 实例TCP协议接入地址（内网）
     */
    private String nameSrvAddr;

    public Properties getMqProperties() {

        Properties properties = new Properties();
        properties.setProperty(PropertyKeyConst.AccessKey, this.accessKeyId);
        properties.setProperty(PropertyKeyConst.SecretKey, this.accessKeySecret);
        properties.setProperty(PropertyKeyConst.NAMESRV_ADDR, this.nameSrvAddr);
        // 设置发送超时时间，单位毫秒
        properties.setProperty(PropertyKeyConst.SendMsgTimeoutMillis, "3000");

        return properties;
    }

    /**
     * 获取消息队列配置
     */
    @Data
    public static class TopicProperties {
        private String topic;
        private String groupId;
        private String tag;
    }
    /**
     * 短信
     */
    @Bean
    @ConfigurationProperties(prefix = "aliyun.mq.sms")
    public TopicProperties smsTopicProperties() {
        return new TopicProperties();
    }
}
